﻿@{
    Layout = "~/Views/Shared/OA/_Index.cshtml";
}
@section Toolbar
{
    @Html.MyNet().Button(new ButtonOptions { Text = "新建", Click = "create" })
    @Html.MyNet().Button(new ButtonOptions { Text = "删除", Click = "removee", Icon = "remove" })
    @Html.MyNet().Button(new ButtonOptions { Text = "设置题型权限", Click = "powerQT" })
    @Html.MyNet().Button(new ButtonOptions { Text = "查看用户", Click = "viewUser" })
}
@section Menu
{
    @Html.MyNet().Menu(new ButtonOptions { Text = "修改", Click = "modify" })
    @if (string.IsNullOrEmpty(Request["Application"]))
    {
        @Html.MyNet().Menu(new ButtonOptions { Text = "设置模块权限", Click = "power" })
    }
    @Html.MyNet().Menu(new ButtonOptions { Text = "设置题型权限", Click = "powerQT" })
    @Html.MyNet().Menu(new ButtonOptions { Text = "删除", Click = "removee", Icon = "remove" })
    @Html.MyNet().Menu(new ButtonOptions { Text = "查看用户", Click = "viewUser" })
}
@section Query
{
    @Html.Partial("_Query", new RoleCondition())
}
@section Main
{
    <div id="grid" class="grid">
    </div>
    <div id="pager" class="pager">
    </div>
}
@Html.Hidden("Application", Request["Application"])
<script>

    var application = $("#Application").val();
    var urlPower = "/Common/Power/";

    var url = "/Common/Role/";
    var urlUser = "/Common/User/";
    jQuery(function () {
        read();
    });

    function read() {
        query.application = application;
        $.ajax
        ({
            url: url + "Read?Application=" + application,
            data: query,
            type: "post",
            error: disposeError,
            success: function (result) {
                if (disposeException(result)) return;
                bind(result);
            }
        });
    }

    function create() {
        nav(url + "Create?Application=" + application);
    }

    function modify() {
        if (!gridSelected()) return alert("未选中任何数据！");
        nav(url + "Modify?Id=" + gridSelected()[0] + "&Application=" + application);
    }

    function viewUser() {
        if (!gridSelected()) return alert("未选中任何数据！");
        nav(urlUser + "Index?RoleId=" + gridSelected()[0] + "&Application=" + application);
    }


    function removee() {
        if (!gridSelected()) return alert("未选中任何数据！");
        if (!confirm("确定要删除选中的数据吗？")) return;

        $.ajax
        ({
            url: url + "Remove",
            data: { ids: gridSelected() },
            type: "post",
            error: disposeError,
            success: function (result) {
                if (disposeException(result)) return;
                read();
            }
        });
    }

    function power() {
        if (!gridSelected()) return alert("未选中任何数据！");
        nav(url + "Power?Id=" + gridSelected()[0] + "&Application=" + application);
    }

    function powerQT() {
        if (!gridSelected()) return alert("未选中任何数据！");
        nav("/TS/UserTreePower/Power?Id=" + gridSelected()[0]);
    }

    function tablePower() {
        if (!gridSelected()) return alert("未选中任何数据！");
        nav(urlPower + "?HumanId=" + gridSelected()[0] + "&HumanType=2&PowerType=2");
    }

</script>
